package billrestauration.entities;

 

 
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.joda.time.DateTime;
import org.springframework.context.annotation.Lazy;

@Entity
@Lazy(value=false)
@Table
public class Reservation {
	public static final int EN_COURS=0X00;
	public static final int TERMINEE=0X01;
	public static final int ANNULEE=0X02;
	
	public Reservation(int status, int nombredepersonne, Utilisateur client,
			Menu menureserve) {
		super();
		this.status = status;
		this.nombredepersonne = nombredepersonne;
		this.client = client;
		this.menureserve = menureserve;
		this.datereservation=new Date ();
	 
	}
	@Override
	public String toString() {
		return "Reservation [id=" + id + ", status=" + status
				+ ", nombredepersonne=" + nombredepersonne + ", client="
				+ client + ", menureserve=" + menureserve
				+ ", datereservation=" + datereservation + "]";
	}
	public Reservation( int nombredepersonne, Utilisateur client,
			Menu menureserve) {
		super();
		this.status = Reservation.EN_COURS;
		this.nombredepersonne = nombredepersonne;
		this.client = client;
		this.menureserve = menureserve;
		this.datereservation=new Date ();
		
	}
	public Reservation(  Utilisateur client,
			Menu menureserve) {
		super();
		this.status = Reservation.EN_COURS;
		this.nombredepersonne = 2;
		this.client = client;
		this.menureserve = menureserve;
		this.datereservation=new Date ();
		
	}
	@Id
	@Column
	@GeneratedValue
private long id;
	@Column
private int status;
	@Column
private int nombredepersonne;
	@ManyToOne(targetEntity=Utilisateur.class)
	@JoinColumn(name="refutilisateur",referencedColumnName="username")
private Utilisateur client;
	@ManyToOne(targetEntity=Menu.class)
	@JoinColumn(name="refmenu",referencedColumnName="id",nullable=true)
private Menu menureserve;
	@Column
private Date datereservation;
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public int getStatus() {
		return status;
	}
	public String getStatusstring() {
		switch (status) {
		case  EN_COURS:
			
			return "Reservation en cours!";
		case ANNULEE: return "Reservation annulée";
    
		default:
			return "Reservation Terminée";
		}
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public int getNombredepersonne() {
		 
		return nombredepersonne;
	}
	public void setNombredepersonne(int nombredepersonne) {
		this.nombredepersonne = nombredepersonne;
	}
	public Utilisateur getClient() {
		return client;
	}
	public void setClient(Utilisateur client) {
		this.client = client;
	}
	public Menu getMenureserve() {
		return menureserve;
	}
	public void setMenureserve(Menu menureserve) {
		this.menureserve = menureserve;
	}
	public Date  getDatereservation() {
		return datereservation;
	}
	public void setDatereservation(Date  datereservation) {
		 
		this.datereservation = datereservation;
	}
	public Reservation(int id, int status, int nombredepersonne,
			Utilisateur client, Menu menureserve, Date  datereservation) {
		super();
		this.id = id;
		this.status = status;
		this.nombredepersonne = nombredepersonne;
		this.client = client;
		this.menureserve = menureserve;
		this.datereservation = datereservation;
	}
	public Reservation() {
		super();
		this.status=Reservation.EN_COURS;
		this.nombredepersonne=1;
		
		// TODO Auto-generated constructor stub
		 
	}
	public boolean getEncours(){return this.datereservation.getTime()<=new Date().getTime()&&this.status==Reservation.EN_COURS;}
	public boolean getAnnulee(){return this.status==Reservation.ANNULEE;}
	public boolean getTerminee(){return this.datereservation.getTime()>new Date().getTime()||this.status==Reservation.TERMINEE;}
	


}
